package cn.com.cetccst.kvmanager;

import android.content.Context;

import com.tencent.mmkv.MMKV;

import java.lang.ref.WeakReference;

public class KVManager {

    public static final int SINGLE_PROCESS_MODE = MMKV.SINGLE_PROCESS_MODE,
            MULTI_PROCESS_MODE = MMKV.MULTI_PROCESS_MODE,
            READ_ONLY_MODE = MMKV.READ_ONLY_MODE;

    private KVManager(){}
    public static class Builder {
        private WeakReference<Context> contextWeakReference;
        private String fileName;
        private int model = SINGLE_PROCESS_MODE;
        private String cryptKey;

        public Builder(Context context) {
            contextWeakReference = new WeakReference<>(context);
        }

        public Builder setFileName(String fileName) {
            this.fileName = fileName;
            return this;
        }

        public Builder setModel(int model) {
            this.model = model;
            return this;
        }

        public Builder setCryptKey(String cryptKey) {
            this.cryptKey = cryptKey;
            return this;
        }

        public IKVStore build() {
            KVStoreImp kvStoreImp = new KVStoreImp(contextWeakReference.get(), fileName, model, cryptKey);
            return kvStoreImp;
        }
    }
}
